package com.gzyj.jtt808.v2011.additionalinfo;

import com.gzyj.jtt808.utils.HexBytesUtil;
import io.netty.buffer.ByteBuf;
import lombok.Data;

import java.io.Serializable;

/**
 * @author lhj
 */
@Data
public class JTT808_0x0200_0x03 extends JTT808_AddtionalInfo implements Serializable {

    private short Speed;

    public JTT808_0x0200_0x03(){
        this.setID(0x03);
        this.setLength(2);
    }

    @Override
    public void encode(ByteBuf buf) {
        buf.writeByte(this.getID());
        buf.writeByte(2);
        buf.writeShort(this.Speed);
    }

    @Override
    public JTT808_0x0200_0x03 decode(ByteBuf buf) {
        byte[] temp= HexBytesUtil.readByOffset(buf,1);
        this.setLength(Integer.parseInt(HexBytesUtil.bytesToHex(temp),16));
        temp=HexBytesUtil.readByOffset(buf,this.getLength());
        this.Speed=Short.parseShort(HexBytesUtil.bytesToHex(temp),16);

        return this;
    }

}
